﻿using ArtheaEngine;
using System.Linq;

namespace ArtheaEngine.Model
{
    public abstract partial class Reset : IEntity
    {
    }

    public abstract partial class SubReset
    {
        public abstract void Execute(IEntity entity);
    }

    public abstract partial class SuperReset
    {
        public abstract void Execute();
    }

    public partial class CharReset
    {
        public override void Execute()
        {
            if (Room.Characters.Where(a => a.Id == Character.Id).Count() >= Count)
                return;


            var ch = Character.Clone();

            foreach (var sub in SubResets)
            {
                sub.Execute(ch);
            }

            Room.Characters.Add(ch);
        }
    }

    public partial class ObjReset
    {
        public override void Execute()
        {
            if (Room.Objects.Where(a => a.Id == Object.Id).Count() >= Count)
                return;

            var obj = Object.Clone();

            foreach (var sub in SubResets)
            {
                sub.Execute(obj);
            }

            Room.Objects.Add(obj);
        }
    }

    public partial class EquipReset
    {
        public override void Execute(IEntity entity)
        {
            Character ch = entity as Character;

            Object obj = Object.Clone();

            ch.Equip(obj, WearLocation);
        }
    }

    public partial class GiveReset
    {
        public override void Execute(IEntity entity)
        {
            Character ch = entity as Character;

            Object obj = Object.Clone();

            ch.Carrying.Add(new CharObj { Object = obj, Character = ch, WearLocation = WearLocation.None });
        }
    }

    public partial class PutReset
    {
        public override void Execute(IEntity entity)
        {
            ContainerObject container = entity as ContainerObject;

            Object obj = Object.Clone();

            container.Contents.Add(obj);
        }
    }
}